package com.hspedu.newData.dmsxl.回溯;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-25 
 * @Version: 1.0
 */

public class LC647回文子串 {

    // todo 需要使用动规，效率很低
    public int countSubstrings(String s) {

        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i; j < s.length(); j++) {
                if (isPalindrome(s.substring(i,j+1))){
                    count++;
                }
            }
        }
        return count;

    }

    public boolean isPalindrome(String s){
        for (int i = 0, j = s.length() - 1; i < j; i++,j--) {
            if (s.charAt(i) != s.charAt(j)){
                return false;
            }
        }
        return true;
    }

    @Test
    public void test() {
        // 测试代码

        countSubstrings("abc");

    }
}
